from building import *

CWD = GetCurrentDir()

# generate(Glob("config/*/*.json"))

objsAddServerEx = Glob("add_server.c")


@register_application
class ApplicationAddServerEx(Application):

    def config(self):
        source = self.Generate(["%s/config/server/Network.json" % (CWD), "%s/config/server/Mempool.json" % (CWD)])
        libsForAddSrv = {
            "SoAd": source["SoAd"] + source["MemCluster"],
            "Sd": source["Sd"],
            "SomeIp": source["SomeIp"],
            "SomeIpXf": source["SomeIpXf"],
        }
        self.CPPPATH = ["$INFRAS", "%s/config/server/GEN" % (CWD)]
        self.source = objsAddServerEx
        self.LIBS = ["TcpIp", "StdTimer", "Critical"]
        self.Append(CPPDEFINES=["USE_TCPIP"])
        for libName, source in libsForAddSrv.items():
            self.LIBS.append(libName)
            self.RegisterConfig(libName, source)
            self.Append(CPPDEFINES=["USE_%s" % (libName.split(":")[0].upper())])

objsAddClientEx = Glob("add_client.c")


@register_application
class ApplicationAddClientEx(Application):

    def config(self):
        source = self.Generate(["%s/config/client/Network.json" % (CWD), "%s/config/client/Mempool.json" % (CWD)])
        libsForAddClient = {
            "SoAd": source["SoAd"] + source["MemCluster"],
            "Sd": source["Sd"],
            "SomeIp": source["SomeIp"],
            "SomeIpXf": source["SomeIpXf"],
        }
        self.CPPPATH = ["$INFRAS", "%s/config/client/GEN" % (CWD)]
        self.source = objsAddClientEx
        self.LIBS = ["TcpIp", "StdTimer", "Critical"]
        self.Append(CPPDEFINES=["USE_TCPIP"])
        for libName, source in libsForAddClient.items():
            self.LIBS.append(libName)
            self.RegisterConfig(libName, source)
            self.Append(CPPDEFINES=["USE_%s" % (libName.split(":")[0].upper())])
